/*
 * created by dt 2025-05-08
 * 技能管理器
 */

import { Component, ecs_component } from "../../core/Component";

@ecs_component("ECSkillManager")
export class ECSkillManager extends Component {
    skills: Skill[] = [];
    private _idToIndex: Map<number, number> = new Map();
    
    // 添加技能
    public addSkill(skill: Skill): void {
        this.skills.push(skill);
        this._idToIndex.set(skill.getInfo().id, this.skills.length - 1);
    }
    
    // 移除技能
    public removeSkill(skillId: number): void {
        const index = this._idToIndex.get(skillId);
        if (index !== undefined) {
            this.skills[index] = this.skills[this.skills.length - 1];
            this.skills.pop();
            this._idToIndex.delete(skillId);
        }
    }
    
    // 获取技能
    public getSkill(skillId: number): Skill | undefined {
        const index = this._idToIndex.get(skillId);
        if (index !== undefined) {
            return this.skills[index];
        }
        return undefined;
    }
    
    onRecycle(): void {
        this.skills.length = 0;
        this._idToIndex.clear();
    }

    onReuse(): void {
    }
}